<?php
/**
 * 
 * ClientEngage: ClientEngage Visitor Voice (http://www.clientengage.com)
 * Copyright 2012, ClientEngage (http://www.clientengage.com)
 *
 * You must have purchased a valid license from CodeCanyon in order to have 
 * the permission to use this file.
 * 
 * You may only use this file according to the respective licensing terms 
 * you agreed to when purchasing this item on CodeCanyon.
 * 
 * 
 * 
 *
 * @author          ClientEngage <contact@clientengage.com>
 * @copyright       Copyright 2013, ClientEngage (http://www.clientengage.com)
 * @link            http://www.clientengage.com ClientEngage
 * @since           ClientEngage - Visitor Voice v 1.0
 * 
 */
?>
<?php
if ($visitorform['Visitorform']['active'] === false)
{
    echo '// ' . __('Visitorform Inactive');
    return;
}
?><?php if (false): ?><script><?php endif; ?>
    function loadJS(callback) {
        var script = document.createElement("script")
        script.type = "text/javascript";
        if (script.readyState) {
            script.onreadystatechange = function() {
                if (script.readyState == "loaded" || script.readyState == "complete") {
                    script.onreadystatechange = null;
                    callback();
                }
            };
        } else {
            script.onload = function() {
                callback();
            };
        }

        script.src = '<?php echo $this->Html->getWebroot() . 'js/jquery/jquery.min.js'; ?>';
        var ph = document.getElementsByTagName('script')[0];
        ph.parentNode.insertBefore(script, ph);
    }

    if (typeof jQuery == 'undefined')
    {
        loadJS(init);
    }
    else
    {
        $(init);
    }
    function init() {
        var cbcss = document.createElement('link');
        cbcss.setAttribute('rel', 'stylesheet');
        cbcss.type = 'text/css';
        cbcss.href = '<?php echo $this->Html->getWebroot() . 'js/colorbox/colorbox.css'; ?>';
        document.body.appendChild(cbcss);
        var cbjs = document.createElement('script');
        cbjs.type = 'text/javascript';
        cbjs.src = '<?php echo $this->Html->getWebroot() . 'js/colorbox/jquery.colorbox-min.js'; ?>';
        document.body.appendChild(cbjs);
        var bcss = document.createElement('link');
        bcss.setAttribute('rel', 'stylesheet');
        bcss.type = 'text/css';
        bcss.href = '<?php echo Router::url(array('controller' => 'visitorforms', 'action' => 'css'), true) . '/' . $slug . '.css'; ?>';
        document.body.appendChild(bcss);
        var buttonContainer = document.createElement('div');
        buttonContainer.id = 'visitorvoiceform_container';
        buttonContainer.style.display = 'none';
        var buttonContainerLink = document.createElement('a');
        buttonContainerLink.href = '#visitorvoiceform';
<?php echo (trim($visitorform['Visitorform']['title_tag']) != '') ? 'buttonContainerLink.title = \'' . $visitorform['Visitorform']['title_tag'] . '\';' : ''; ?>
        buttonContainerLink.onclick = function() {
            vvPath = '<?php echo Router::url(array('controller' => 'visitorforms', 'action' => 'get', $slug, 'ref' => base64_encode($referer)), true); ?>';
            if (/Android|webOS|iPhone|iPad|iPod|BlackBerry/i.test(navigator.userAgent))
            {
                window.open(vvPath);
                return false;
            }
            $('#visitorvoiceform_container').fadeOut();
            $.colorbox({iframe: true, href: vvPath, width: "<?php echo $visitorform['Visitorform']['modal_width']; ?>", height: "<?php echo $visitorform['Visitorform']['modal_height']; ?>", fixed: true, overlayClose: false, onClosed: function() {
                    $('#visitorvoiceform_container').fadeIn();
                }});
            return false;
        }

        buttonContainerLink.appendChild(buttonContainer);
        $('body').append(buttonContainerLink);
        $('#visitorvoiceform_container').fadeIn();
    }
<?php if (false): ?></script><?php endif; ?>